package com.lkm.market2_0.m_imple.steelyardserver.server.cmd_handle;

import com.lkm.javatool.CollectionHelp;
import com.lkm.javatool.NumberHelp;
import com.lkm.market2_0.ExpandConfig;
import com.lkm.market2_0.m.steelyarddata.SteelyardDataModule;
import com.lkm.market2_0.m.steelyarddata.SteelyardValue;
import com.lkm.market2_0.m.steelyardserver.SteelyardServerModule;
import com.lkm.market2_0.m_imple.steelyardserver.server.AbsReceiverDataHandle;
import com.lkm.market2_0.m_imple.steelyardserver.server.CMDEntity;
import com.lkm.market2_0.m_imple.steelyardserver.server.ICMDHandle;

import java.util.Arrays;



public class CMDInitValue0Handle implements ICMDHandle {

    SteelyardDataModule mSteelyardDataModule;
    SteelyardServerModule mSteelyardServerModule;

    public CMDInitValue0Handle() {
        this.mSteelyardDataModule = ExpandConfig.instance.getModuleManager().loadModule(SteelyardDataModule.class);
        this.mSteelyardServerModule = ExpandConfig.instance.getModuleManager().loadModule(SteelyardServerModule.class);
    }

    public static void main(String[] args) {
        byte[] s = "89860619100084692054".getBytes();
        System.out.println(s);
    }



    @Override
    public AbsReceiverDataHandle handle(CMDEntity cmdEntity) {

        
        byte[] numByte = NumberHelp.intToBytesDesc(cmdEntity.getNum());
        byte[] datas = CollectionHelp.concatByte(new byte[]{numByte[2], numByte[3]}, cmdEntity.getData());

        if (this.mSteelyardDataModule == null) {
            this.mSteelyardDataModule = ExpandConfig.instance.getModuleManager().loadModule(SteelyardDataModule.class);
        }

        SteelyardValue steelyardValue = null;
        if(mSteelyardDataModule!=null)
            steelyardValue = mSteelyardDataModule.getSteelyardValue(cmdEntity.getSteelyardMac());
        if(steelyardValue==null)
            steelyardValue = new SteelyardValue();


        steelyardValue.steelyardMac = cmdEntity.getSteelyardMac();

        try {
            String ccid = new String(Arrays.copyOfRange(datas, 0, 20),"utf-8");
            steelyardValue.ccid = ccid;
        }catch (Exception e){}


        if(mSteelyardDataModule!=null)
            mSteelyardDataModule.regSteelyardValue(steelyardValue);


        return null;
    }



}
